import { ctx } from "./canvas.js";
const HP_bar=document.querySelector('.hp')

const user_plane= function () {
  this.life = 20;
  this.MAX_HP=20
  this.atk_level = 1;
  this.bullet_style=1;
  this.speed = 10;
  this.unbeatable_time = false;
  this.left = 500;
  this.top = 500;
  this.width = 40;
  this.height = 60;
  this.wingman=false;
  this.foot_animate=[document.getElementById('foot'),document.getElementById('foot1')]
  this.foot_index=0
  this.dom = document.getElementById("plane");
  this.foot=()=>{
    ctx.drawImage(this.foot_animate[this.foot_index],this.left+this.width/2+10-7,this.top+this.height-10)
    ctx.drawImage(this.foot_animate[this.foot_index],this.left+this.width/2-10-7,this.top+this.height-10)
  }
  const jianbian =ctx.createRadialGradient(this.height/2,this.height/2,0,this.height/2,this.height/2,this.height/2)
  jianbian.addColorStop(0,'rgba(0,0,255,0)')
  jianbian.addColorStop(1,'rgba(0,255,0,1)')
  this.unbeatable = () => {
    this.unbeatable_time = true;
    setTimeout(() => {
      this.unbeatable_time = false;
    }, 1000);
  };
  this.drawCovered = () => {
    ctx.beginPath()
    ctx.moveTo(this.left, this.top)
    ctx.arc(this.left+this.width/2, this.top+this.height/2, this.height/2, 0, 2*Math.PI)
    ctx.fillStyle= "rgba(0,0,255,0.5)";//设置填充颜色
    ctx.fill();//开始填充
   
  }
  this.changeHP = (num) => {
    if(this.unbeatable_time) return
    this.life+=num
    HP_bar.style.width=287*(this.life/this.MAX_HP)+'px'
    if(num<0){
      this.unbeatable()
    }
  }
}
const bullet_list=[]
const skill_list=[]
export {bullet_list,user_plane,skill_list}